import request from '../utils/request';

// 薪资管理相关API
export const salaryApi = {
  // 获取薪资列表
  getSalaryList: (params) => {
    return request.get('/api/salary', { params });
  },

  // 获取薪资详情
  getSalaryDetail: (id) => {
    return request.get(`/api/salary/${id}`);
  },

  // 创建薪资记录
  createSalary: (data) => {
    return request.post('/api/salary', data);
  },

  // 更新薪资记录
  updateSalary: (id, data) => {
    return request.put(`/api/salary/${id}`, data);
  },

  // 删除薪资记录
  deleteSalary: (id) => {
    return request.delete(`/api/salary/${id}`);
  },

  // 批量导入薪资
  importSalary: (file) => {
    const formData = new FormData();
    formData.append('file', file);
    return request.post('/api/salary/import', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },

  // 导出薪资表
  exportSalary: (params) => {
    return request.get('/api/salary/export', { 
      params,
      responseType: 'blob'
    });
  },

  // 获取薪资统计
  getSalaryStatistics: (params) => {
    return request.get('/api/salary/statistics', { params });
  },

  // 获取薪资模板
  getSalaryTemplates: () => {
    return request.get('/api/salary/templates');
  },

  // 创建薪资模板
  createSalaryTemplate: (data) => {
    return request.post('/api/salary/templates', data);
  },

  // 更新薪资模板
  updateSalaryTemplate: (id, data) => {
    return request.put(`/api/salary/templates/${id}`, data);
  },

  // 删除薪资模板
  deleteSalaryTemplate: (id) => {
    return request.delete(`/api/salary/templates/${id}`);
  },

  // 计算薪资
  calculateSalary: (data) => {
    return request.post('/api/salary/calculate', data);
  },

  // 发放薪资
  paySalary: (id, data) => {
    return request.post(`/api/salary/${id}/pay`, data);
  },

  // 获取薪资历史
  getSalaryHistory: (employeeId, params) => {
    return request.get(`/api/salary/employee/${employeeId}/history`, { params });
  }
};
